home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Programming / FreshBar / Source / FreshBar.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-01  |  5.7 KB  |  258 lines

  1. //****************************************************************//
  2. // Filename:    FreshBar.cpp
  3. // Autor:       Christian Taulien of Strange Intelligence
  4. // Purpose:     Testprogram for the SIFC
  5. // Creation:    10. Mai 1998
  6. //****************************************************************//
  7.  
  8. #include <iostream.h>
  9. #include <string.h>
  10.  
  11. #include <exec/types.h>
  12. #include <exec/memory.h>
  13. #include <rexx/storage.h>
  14. #include <intuition/intuition.h>
  15. #include <libraries/gadtools.h>
  16.  
  17. #include <clib/exec_protos.h>
  18. #include <clib/dos_protos.h>
  19. #include <clib/alib_protos.h>
  20. #include <clib/rexxsyslib_protos.h>
  21. #include <clib/gadtools_protos.h>
  22. #include <clib/intuition_protos.h>
  23.  
  24. #include "global.h"
  25. #include "VisualInfo.h"
  26. #include "FreshLocale.h"
  27. #include "internalcatalog.h"
  28. #include "FreshBar_ARexxPort.h"
  29. #include "WindowList.h"
  30.  
  31. /*S*/ // Variablendefs
  32. struct Library *DosBase;
  33. struct Library *IntuitionBase;
  34. struct Library *GfxBase;
  35. struct Library *RexxBase;
  36. struct Library *GadToolsBase;
  37. struct Library *LocaleBase;
  38. struct Window *mainwindow=NULL;
  39. CatalogC *glob_poCatalog = NULL;
  40. FreshBarARexxPortC *glob_poARexxPort = NULL;
  41. BarWindowListC *glob_poBWList = NULL;
  42. /*E*/
  43. /*S*/ // WindowStuff
  44. // *********************** Start der Window UP's ***************************
  45. void RemoveMsgFromMainWindow(void)
  46. /*S*/
  47. {
  48. struct IntuiMessage *imsg;
  49.   TRACE("Entry");
  50.   if (mainwindow)
  51.   {
  52.     while (imsg=GT_GetIMsg(mainwindow->UserPort))
  53.     {
  54.       GT_ReplyIMsg(imsg);
  55.     } // while
  56.   } // if
  57. }
  58. /*E*/
  59. void CloseMainWindow(void)
  60. /*S*/
  61. {
  62.   TRACE("Entry");
  63.   RemoveMsgFromMainWindow();
  64.   if (mainwindow)
  65.   {
  66.     CloseWindow(mainwindow);
  67.     mainwindow = NULL;
  68.   } // if
  69. }
  70. /*E*/
  71. BOOL MainWindowHandler(struct IntuiMessage *imsg)
  72. /*S*/
  73. // Behandelt Ereignisse des Control Panels
  74. {
  75. LONG myevent=imsg->Class;
  76. APTR myiaddress=imsg->IAddress;
  77. WORD mycode=imsg->Code;
  78. BOOL done = FALSE;
  79. // ULONG myqualifier=imsg->Qualifier;
  80.     TRACE("Entry");
  81.     GT_ReplyIMsg(imsg);
  82.     switch (myevent)
  83.     {
  84.       case IDCMP_CLOSEWINDOW:
  85.         done = TRUE;
  86.         break;
  87.     } // switch
  88.  
  89.     // entprellen
  90.     if (mainwindow)
  91.     {
  92.       while (imsg=GT_GetIMsg(mainwindow->UserPort))
  93.       {
  94.         GT_ReplyIMsg(imsg);
  95.       } // if
  96.     } // if
  97. return done;
  98. }
  99. /*E*/
  100. // *********************** Ende der Window UP's ****************************
  101. /*E*/
  102. /*S*/ // Library Stuff
  103. // ********************** START der Libs UP's *************************
  104. void CloseLibs(void)
  105. /*S*/
  106. // Schließen aller geöffneten Libs
  107. {
  108.   TRACE("Entry");
  109.   if (GfxBase)
  110.   {
  111.     CloseLibrary(GfxBase);
  112.     GfxBase=NULL;
  113.   } // if
  114.  
  115.   if (IntuitionBase)
  116.   {
  117.     CloseLibrary(IntuitionBase);
  118.     IntuitionBase=NULL;
  119.   } // if
  120.  
  121.   if (DosBase)
  122.   {
  123.     CloseLibrary(DosBase);
  124.     DosBase=NULL;
  125.   } // if
  126.  
  127.   if (RexxBase)
  128.   {
  129.     CloseLibrary(RexxBase);
  130.     RexxBase=NULL;
  131.   } // if
  132.  
  133.   if (GadToolsBase)
  134.   {
  135.     CloseLibrary(GadToolsBase);
  136.     GadToolsBase = NULL;
  137.   } // if
  138.  
  139.   if (::LocaleBase)
  140.   {
  141.     CloseLibrary(::LocaleBase);
  142.     ::LocaleBase = NULL;
  143.   } // if
  144. }
  145. /*E*/
  146. BOOL OpenLibs(void)
  147. /*S*/
  148. // Öffnen aller benötigten Libs
  149. {
  150.   TRACE("Entry");
  151.   if (IntuitionBase=OpenLibrary("intuition.library",39L))
  152.   {
  153.     if (GfxBase=OpenLibrary("graphics.library",39L))
  154.     {
  155.       if (DosBase=OpenLibrary("dos.library",36L))
  156.       {
  157.         if (RexxBase=OpenLibrary(RXSNAME,NULL))
  158.         {
  159.           if (GadToolsBase=OpenLibrary("gadtools.library", 39L))
  160.           {
  161.             if (::LocaleBase=OpenLibrary("locale.library", 39L))
  162.             {
  163.               return TRUE;
  164.             } else TRACE("Failed to open locale.library v39");
  165.           } else TRACE("Failed to open gadtools.library v39");
  166.         } else TRACE("Failed to open rexxsyslib.library");
  167.       } else TRACE("Failed to open dos.library v36");
  168.     } else TRACE("Failed to open graphics.library v39");
  169.   } else TRACE("Failed to open intuition.library v39");
  170.   CloseLibs();
  171. return FALSE;
  172. }
  173. /*E*/
  174. // ********************** ENDE der Libs UP's *************************
  175. /*E*/
  176. /*S*/ // Controller
  177. void Controller(void)
  178. /*S*/
  179. // Dieses UP ermöglicht asynchrone Bedienung!!!
  180. {
  181. BOOL done=FALSE;
  182.   TRACE("Entry");
  183.   while (!done)
  184.   {
  185.     ULONG signalbits=NULL,erhaltene_signale;
  186.     struct IntuiMessage *imsg;
  187.     // Sammeln der SignalBits der einzelnen Fenster
  188.     if (glob_poARexxPort)
  189.     {
  190.       signalbits=1L<<glob_poARexxPort->getMsgPort()->mp_SigBit;
  191.     } // if rexxhost
  192.  
  193.     if (mainwindow)
  194.     {
  195.       signalbits|=1L<<mainwindow->UserPort->mp_SigBit;
  196.     } // if mainwindow
  197.  
  198.     if (signalbits) // wenn überhaupt ein Bit gesammelt wurde
  199.     {
  200.       erhaltene_signale=Wait(signalbits);
  201.       if (glob_poARexxPort)
  202.       {
  203.         if (erhaltene_signale & (1L<<glob_poARexxPort->getMsgPort()->mp_SigBit))
  204.         {
  205.           done=glob_poARexxPort->processARexxCommand();
  206.         } // if
  207.       }
  208.       if (!done)
  209.       {
  210.         if (mainwindow)
  211.         {
  212.           if (((erhaltene_signale) & (1L<<mainwindow->UserPort->mp_SigBit)) && (imsg=GT_GetIMsg(mainwindow->UserPort)))
  213.           {
  214.             done=MainWindowHandler(imsg);
  215.           } // if
  216.         } // if
  217.       }
  218.       else
  219.       {
  220.         RemoveMsgFromMainWindow();
  221.       } // if not done
  222.     }
  223.     else
  224.     {
  225.       done=TRUE;
  226.     } // if signalbits are vorhanden
  227.   }
  228.   CloseMainWindow();
  229. }
  230. /*E*/
  231. /*E*/
  232.  
  233. void main()
  234. /*S*/
  235. {
  236.   TRACE("Entry");
  237.   char glob_version[]="$VER: FreshBar 1.1 (98-08-01)\0";
  238.   if (OpenLibs())
  239.   {
  240.     if (glob_poCatalog = new CatalogC("FreshBar.catalog", 1, NULL))
  241.     {
  242.       if (glob_poARexxPort = new FreshBarARexxPortC("FRESHBAR_REXX"))
  243.       {
  244.         if (glob_poBWList = new BarWindowListC)
  245.         {
  246.           Controller();
  247.           delete glob_poBWList;
  248.         } // if
  249.         delete glob_poARexxPort;
  250.       } // if
  251.       delete glob_poCatalog;
  252.     } // if
  253.     CloseLibs();
  254.   } // if
  255. } // main()
  256. /*E*/
  257.  
  258.